/*
 * GoTreeCellRenderer.java
 *
 * Created on August 23, 2007, 6:23 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.psu.bd.math.grooms;

import java.awt.Component;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 *
 * @author joe
 */
public class GoTreeCellRenderer extends DefaultTreeCellRenderer{
    
    
    private final ImageIconScalable whiteIcon;
    private final ImageIconScalable blackIcon;
    
    
    /** Creates a new instance of GoTreeCellRenderer */
    public GoTreeCellRenderer() {
        ImageIcon tmpIcon = (ImageIcon) this.getOpenIcon();
        int h = tmpIcon.getIconHeight();
        int w = tmpIcon.getIconWidth();
        
        
        tmpIcon = (ImageIcon)
        org.cgsuite.plugin.PluginUtilities.getIcon(
                org.cgsuite.plugin.PluginUtilities.WHITE_STONE);
        Image i = tmpIcon.getImage();
        
        whiteIcon = new ImageIconScalable (i);
        
        tmpIcon = (ImageIcon)
        org.cgsuite.plugin.PluginUtilities.getIcon(
                org.cgsuite.plugin.PluginUtilities.BLACK_STONE);
        i = tmpIcon.getImage();
        
        blackIcon = new ImageIconScalable(i);
        whiteIcon.setScaledSize(w,h);
        blackIcon.setScaledSize(w,h);
    }
    
     public Component getTreeCellRendererComponent(
            JTree tree,
            Object value,
            boolean sel,
            boolean expanded,
            boolean leaf,
            int row,
            boolean hasFocus) {
        
        super.getTreeCellRendererComponent(
                tree, value, sel,
                expanded, leaf, row,
                hasFocus);
        switch (getColor(value)) {
            case GoRoom.WHITE_STONE:
                
                setIcon(whiteIcon);
                break;
            case GoRoom.BLACK_STONE:
                setIcon(blackIcon);
                break;
            case GoRoom.EMPTY:
                setIcon(whiteIcon);
                break;
                
                
                
                
        }
        
        return this;
    }
    
    protected int getColor(Object value) {
        GoRoom node =
                (GoRoom)value;
        
        return node.getLastColor();
        
        
    }
    
    
    
}
